Hello and welcome.
In this lecture we are going to create the functionality for our app using javascript as a programmer
when you have a project to do his best to try as much as possible to break them down in lead to small
actionable steps that will together collectively build the projects.
So these are the steps I have taken to bring down our own task.
So first we need to determine a way to generate a random number between 1 and 500.
Okay next we need to display the previous numbers that have been guessed.
We need to find the way to do that.
Next we need to keep a record of the numbers of attempted guesses followed by this.
We need to display the guesses are wrong and so we need to give the player a clue as to if the guesses
were too high or too low.
Once we also need to find a way to make the game over once the ones they've had ten attempts Okay someone
had 10 up 10.
We need to make sure the game is over and disable the inputs so they can't add any more guesses.
The only way they can really read play the game is to restart it.
So we now look for a way to create the restart button that will allow them to start the game again.
So that's the plan.
The first thing we're going to do we are going to create some variables that we can use to store our
data.
So these are the variables I have created that will use to store the data to create variable you just
type in the key word var followed by the name you want to give the variable variable on line on line
of chord random number.
This is what we'll use to generate the random number between one and five hundred.
So this is calculated using a mathematical algorithm saw using the maths floor method and also we passed
it.
We've passed another method of function into it called Mat's dot random mass.
Top floor archly.
What it does it rounds the number up into the nearest whole number.
Why the mass around is the one that generates the actual random numbers and you've got a.
Times 500 which is the actual number that we all.
That's the maximum and then the plus 1 means you can increase it for anything from zero.
Ok to that 500 line to 3 and 4 are used to store a reference to the result paragraph in our hasty email.
So they will be used to insert values into the paragraphs later on in the code.
The variables on line 5 and 6 are used to store references to the form text input and the submit button.
Okay so they are used to store references to the text input from the form and the submit button and
also they are used to control the Submitting of the guesses.
So later on where you'd be able to submit the guess numbers you used that to control that as well.
The variable on line 7 is used to store a guess count of 1 so is it just the count as he stalls the
number of times that the player has tried.
So he stores a count of 1 which it uses to track how many guesses the player has had while Line 8 is
a reference to the reset button will be creating the button late out so once the game is over and all
the attempts have been use your King press the reset button and the game can be restarted.
I have added a function on line 10 here all the way to line 39.
Call the function check guess saw line 11.
We have declared a variable chord use that guess and set the value to the current value entered inside
the text field.
Right so we also can run these value through the built in number method.
Just make sure the value is definitely in number line 12.
We've got a conditional statement an if statement.
So what the first condition listed menhir from line 12.
Basically conditional code block allows you to run a chord selectively depending on whether it is setting
condition is true or not.
So it looks a bit like a function but not quite function.
So the simplest form of a conditional block starts with a key word.
If he has used the word if on line 12 right then you have some parent he sees.
Then some curly braces inside the parent.
This is we include a test or a check condition.
If the test returns true were wrong the code inside the curly braces.
If the test is false we dont.
We move on to the next bit of code.
In this case the test is tense checking whether the game.
Count variable is equal to one that is whether this is the player's first attempt or not.
It is online talk here we've used troops.
It was to watch me strictly If the guest count is strictly was to one.
So what the saying that if the guess is true if it's a course of one and we make the guests This paragraph
text is Walt's two previous guesses.
If not we don't.
Okay.
The next line of course says the current use I guess value or at current use I guess value that is the
guess is they have made the current user go on line 15.
What the court is saying is that it's give the user an option to enter at a guess and he can see of
what he uses and it guess you Sim plus operator there be blank quotes.
So that's where the text number will go.
The guess number an online 16 we've attached here.
Background call law as a start.
So what.
Or the guess is that the play makes will be recorded on that blue strip of background colour line 17
saying that if the number that the users guess is the random number it the last result the text for
the last result if it matches.
Okay if the last resort does text content if it is a right number then you display a message saying
congratulations you got it right and then it will display a green banner to show the colour.
Right.
Line 20 law high Tex gives a value.
If the number gets is low or high line 12 one is this set game or that function is called Win.
All the attempts have been used.
Line 22 sane is an else if statement.
The first condition is not true if instead most sane even against count is strictly a cost of 10 that
is abused or their attempt then the last resort the last attempt.
You displayed a test game over them used all detent attempt and then you display low or high.
Don't text content so you display the content where this it was to.
You've got the quotes here.
Weakness.
Whatever the end time detects.
That's where it will go so it will display the last text.
It be no their guess was low or high and in the game your skill causes function say is set.
Game over.
Else this condition will applaud.
These are conditional statements.
So if not this will happen.
We'll see.
Last resort techs who tell you you've got the answer wrong it will display a background colour of red
and will show you all the random numbers that there has been guess who display the black background
will be red.
We are showing you are wrong.
And then Honda made the background online 30 dahlby a text that says the number you guessed was too
low land 31st else.
If if you did no yes it is higher than the random number you display a text saying last guess was too
high.
Alright service low line 20 line in the guess the play I guess is less than they displayed random number
it displays your.
It displays a text to say the number guest is too low.
Whereas on line 31 it does the opposite.
Line thirty six.
It requires a count of the attempt so every attempt you have records the tap the 10 the plus plus moves
it and the increment.
It keeps the increase in it and then the geathers value gets filled here.
Online 37 equals 2.
That's where you entail your tax.
The geathers field for Kwas basically is used to foreclose on that input Botting forces mouse on the
input button.
So we are going to end this show here and continue in Part 2.
Thanks for watching.